package demo6;

import java.time.LocalDate;

// 显示万年历：输入年份和月份，显示当月日历

public class Calendar01 {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // System.out.println("请输入年月");
        // int y = sc.nextInt();
        // int m = sc.nextInt();
        // printCalendar(y, m);

        for(int i=1;i<=12;i++) {
            printCalendar(2021, i);
            printCalendar1(2021, i);
        }
    }
    public static void printCalendar1(int y, int m) {
        LocalDate date = LocalDate.of(y, m, 1);
        // System.out.println(date);
        int w = date.getDayOfWeek().getValue();// 1-7 周一-周日
        // System.out.println(w);
        int maxDate =
                date.plusMonths(1).minusDays(1).getDayOfMonth();
        // System.out.println(maxDate);
        System.out.println();
        System.out.println("\t" + y + "年" + m + "月");
        System.out.println("一\t二\t三\t四\t五\t六\t日");
        for(int i=0;i<w-1;i++) {
            System.out.print("\t");
        }
        for (int i = 1; i <= maxDate; i++) {
            System.out.print(i+"\t");
            if((i+w-1)%7==0) {
                System.out.println();
            }
        }
    }
    public static void printCalendar(int y, int m) {
        LocalDate date = LocalDate.of(y, m, 1);
        System.out.println();
        System.out.println("\t" + y + "年" + m + "月");
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        int w = date.getDayOfWeek().getValue();//1-7 周一-周日
        for(int i=0;i<w&&w!=7;i++) {
            System.out.print("\t");
        }
        while(date.getMonthValue()==m) {
            System.out.print(date.getDayOfMonth()+"\t");
            if(date.getDayOfWeek().getValue()==6) {
                System.out.println();
            }
            date = date.plusDays(1);
        }
    }
}
